<template>
<view class="container">
  <!-- <view class="tixian_top">
    <text class="tixian_text">提现到微信零钱</text>
    <text class="tixian_limit">每日可提现5次</text>
  </view> -->
  <view class="tixian_box">
    <view class="tixian_account">提现金额</view>
    <view class="tixian_input">
      <text style="margin-right:10rpx;">￥</text>
      <input placeholder-class="tixian_input_font" class="tixian_input_font" placeholder="00.00" auto-focus :value="money" @input="getBuyerScript"></input>
    </view>
    <!-- <view class='tixian_item'>
      <text style='margin-right:20rpx;'>真实姓名:</text>
      <input class='tixian_item_input' placeholder="微信绑定的真实姓名" value='{{reqUserTrueName}}' bindinput='getUserTrueName'></input>
    </view> -->
    <view style="font-size:24rpx;margin-top:10rpx;color:#888" v-if="fxDetail&&fxDetail.fxSetting.tixianRemark">Tip：{{fxDetail.fxSetting.tixianRemark}}</view>
    <!-- <view style="font-size:24rpx;margin-top:10rpx;color:#888">提现金额不得少于<text :style="'color:' + setting.platformSetting.defaultColor">￥1.00</text>元，可提金额<text :style="'color:' + setting.platformSetting.defaultColor">￥{{mendian.account.account}}</text>元</view>
    <view class style="font-size:24rpx;margin-top:16rpx;color:#888">
      <view style="margin-right:20rpx">每次最高提现金额<text :style="'color:' + setting.platformSetting.defaultColor">￥500.00</text>元，每天提现<text :style="'color:' + setting.platformSetting.defaultColor">￥2500.00</text>元封顶</view>
    </view> -->
    <!-- <view class='tixian_tip'>
      <text></text>
    </view> -->
    <view class="tixian_btn" :style="'background:' + (agree?setting.platformSetting.defaultColor:'#ddd')" @tap="subMitButn">
      <text>提现</text>
    </view>
  </view>
</view>
</template>

<script>

export default {
  data() {
    return {
      money: 1,
      butn_show_loading: false,
      userInfo: null,
      agree: false,
      extraData: {},
      setting: "",
      fxDetail:null,
      loginUser: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {//this.getSessionUserInfo()
    this.get_fx_detailFun()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting
    });
    this.setData({
      loginUser: getApp().globalData.loginUser
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.get_fx_detailFun()
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  methods: {
    //获取推广中心，查看是否有资格
    get_fx_detailFun: function (setting) {
      console.log('-------推广中心--------');
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_fx_data.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===get_fx_detail===", res);
          let fxDetail = res.data.relateObj;
          if (res.data.errcode == '0') {
            that.setData({
              fxDetail: fxDetail
            });
          }
          that.getSessionUserInfo(fxDetail);
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    getSessionUserInfo: function (fxDetail) {
      var that = this;
      getApp().globalData.showToastLoading('loading', true);
      var postParamUserBank = getApp().globalData.AddClientUrl("/get_session_userinfo.html");
      wx.request({
        url: postParamUserBank.url,
        data: postParamUserBank.params,
        header: getApp().globalData.headerPost,
        success: function (res) {
          console.log(res.data);
          let data = res.data.relateObj.platformUser;

          if (res.data.errcode == '0') {
            if (data.trueName ||(data.trueName &&(fxDetail.fxSetting.weixinTixian==1||(fxDetail.fxSetting.yinhangTixian==1&&data.bankName && data.subBankName && data.bankNo) || (fxDetail.fxSetting.zhifubaoTixian==1&&data.zfbNo)))) {
              that.agree = true;
              that.setData({
                agree: that.agree,
                extraData: {
                  reqBankName: data.bankName + data.subBankName,
                  reqBankCardNo: data.bankNo,
                  reqUserTrueName: data.trueName
                }
              });
              console.log("extraData", that.extraData);
            } else {
              that.agree = false;
              that.setData({
                agree: that.agree
              });
            }

            that.setData({
              userInfo: data
            });
          } else {
            wx.showToast({
              title: res.data.errMsg,
              image: '/images/icons/tip.png',
              duration: 1000
            });
          }
        },
        fail: function (res) {
          wx.hideLoading();
          wx.showToast({
            title: "请求错误",
            image: '/images/icons/tip.png',
            duration: 1000
          });
          console.log(res.data);
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    getBuyerScript: function (e) {
      this.setData({
        money: e.detail.value
      });
    },
    subMitButn: function () {
      var that = this;
      let money = Number(this.money);

      if (money < 0 || money == 0) {
        return;
      }

      if (!that.agree) {
        wx.showModal({
          title: '提示',
          content: '主人~您还没填写详细信息哦，点击确定前往填写!',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
              that.tolinkUrl("user_bank_info_setting.html");
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
        return;
      }

      let wxChatPayParam = {
        amount: ''
      };
      wxChatPayParam.amount = Number(money);
      wxChatPayParam = Object.assign({}, wxChatPayParam, that.extraData);
      this.setData({
        butn_show_loading: true
      });
      let customIndex = getApp().globalData.AddClientUrl("/req_tixian.html", wxChatPayParam, 'post');
      wx.showModal({
        title: '提示',
        content: '确认提现？',
        success: function (res) {
          if (res.confirm) {
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: getApp().globalData.headerPost,
              method: 'POST',
              success: function (res) {
                console.log(res);

                if (res.data.id) {
                  wx.showToast({
                    title: '提交成功',
                    icon: 'success',
                    duration: 2000
                  });
                  setTimeout(function () {
                    wx.navigateBack();
                  }, 2000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg,
                    image: '/images/icons/tip.png',
                    duration: 2000
                  });
                }
              },
              fail: function () {},
              complete: function () {
                that.setData({
                  butn_show_loading: false
                });
              }
            });
          } else if (res.cancel) {
            that.setData({
              butn_show_loading: false
            });
            console.log('用户点击取消');
          }
        }
      });
    },

    /* 组件事件集合 */
    tolinkUrl: function (data) {
      let linkUrl = data.currentTarget ? data.currentTarget.dataset.link : data;
      console.log("==linkUrl===", linkUrl);
      getApp().globalData.linkEvent(linkUrl);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>